import 'package:flutter/material.dart';
import 'package:fsharing/ui/pages/mine/order/order_list_page.dart';
import 'package:fsharing/ui/widgets/background_container.dart';
import 'package:fsharing/ui/widgets/round_back_button.dart';

/// 订单参数
class OrderPageArgs {
  final int storeId;
  final int index;

  OrderPageArgs(this.storeId, this.index);
}

/// 订单tab页面
class OrderPage extends StatelessWidget {
  final OrderPageArgs args;
  final List<String> tabLabels = <String>['待付款', '待发货', '待收货', '全部订单'];

  OrderPage({
    Key key,
    @required this.args,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BackgroundContainer(
      child: Scaffold(
        appBar: AppBar(
          leading: RoundBackButton(),
          title: Text(args.storeId == null ? '我的订单' : '店铺订单'),
        ),
        body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 12),
          child: DefaultTabController(
            length: tabLabels.length,
            initialIndex: args.index,
            child: Column(
              children: <Widget>[
                Container(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage('assets/images/cart/img_store.png'),
                      fit: BoxFit.fill,
                    ),
                  ),
                  height: 45,
                  child: Container(
                    height: 20,
                    child: TabBar(
                      isScrollable: true,
                      indicator: BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage('assets/images/order/img_item_selected.png'),
                          fit: BoxFit.fill,
                        ),
                      ),
                      indicatorSize: TabBarIndicatorSize.label,
                      indicatorWeight: 0,
                      tabs: List.generate(tabLabels.length, (index) {
                        return Tab(
                          child: Container(
                            alignment: Alignment.center,
                            padding: EdgeInsets.symmetric(horizontal: 5),
                            decoration: BoxDecoration(
                              image: DecorationImage(
                                image: AssetImage('assets/images/order/img_item_normal.png'),
                                fit: BoxFit.fill,
                              ),
                            ),
                            constraints: BoxConstraints(
                              minWidth: 55,
                              minHeight: 20,
                            ),
                            child: Text(
                              tabLabels[index],
                              style: TextStyle(fontSize: 14),
                            ),
                          ),
                        );
                      }),
                    ),
                  ),
                ),
                Expanded(
                  child: TabBarView(
                    children: List.generate(
                      tabLabels.length,
                      (index) => OrderListPage(
                        storeId: args.storeId,
                        index: index,
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
